// BaseLex.cpp: implementation of the BaseLex class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "8085.h"
#include "BaseLex.h"
#include <stdio.h>

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

BaseLex::BaseLex()
{
    Init();
}

BaseLex::BaseLex(char *str)
{
    SetBuffer(str);
}

BaseLex::~BaseLex()
{

}

//////////////////////////////////////////////////////////////////////
// Implementation
//////////////////////////////////////////////////////////////////////
void BaseLex::Init()
{
    m_szBuffer[0] = '\0';
    m_pStr = NULL; //m_szBuffer;
    m_nToken = 0;
    m_szToken[0] = '\0';
}

int BaseLex::NextToken(void)
{
    if(NULL==m_pStr) return EOLN;
    while(isspace(*m_pStr) || (*m_pStr=='\n')) ++m_pStr;
    if(m_pStr[0]=='\0')
    {
        m_pStr = NULL;
        return EOLN;
    }
    return 1;
}

int BaseLex::Advance(void)
{
    return m_nToken = NextToken();
}

char * BaseLex::Read(FILE * m_hInfile)
{
    //Init();
    if(fgets(m_szBuffer,GetBufferLen(),m_hInfile))
        return m_pStr = m_szBuffer;
    else return NULL;
}

// The only function through exceptions are thrown throughout
// the parser
void BaseLex::ThrowException(severity s,the_exceptions e, const CString& str)
{
    throw CMyException(s,e,GetErrorPrefix()+str);
}

CString BaseLex::GetErrorPrefix()
{
    return m_szErrorPrefix;
}